$(document).ready( function () {
 
	Cufon('.hel', { hover: true, fontFamily: 'hel' });
  Cufon.now();
  
  Image1 = new Image(949,244)
  Image1.src = "../img/banner/experience-bg.jpg"
  Image2 = new Image(949,244)
  Image2.src = "../img/banner/learn-bg.jpg"
  Image3 = new Image(949,244)
  Image3.src = "../img/banner/network-bg.jpg"
  Image4 = new Image(949,244)
  Image4.src = "../img/banner/discover-bg.jpg"
  Image5 = new Image(949,244)
  Image5.src = "../img/banner/register-bg.jpg"

  // banner
  $('#banner .banner .nav li a').hover(
    function() {
      var newbanner = $(this).parent().attr('class');
      $('#banner > div').hide();
      $('#banner div.' + newbanner).show();
      $('#banner div.' + newbanner + ' > ul.nav').addClass('active');
      $('#banner .textbox').show();
    });
    
    $('#banner').mouseleave(function() {
      $('#banner .banner .nav').removeClass('active');
      $('#banner .textbox').hide();
    });
  
  // accordian
  $('.acdlist a.opener').click(function(){
    var clicktitle = $(this).parents('dt');

  	if( clicktitle.next().is(':hidden') ) {
      $('.acdlist dd').slideUp();
  		$('#acdlist dt.active').removeClass('active').next().slideUp(); 
  		clicktitle.toggleClass('active').next('dd').slideDown(); 
  	} else {
  	  clicktitle.toggleClass('active').next('dd').slideUp();
  	}
  	return false;
  });
  
  // search function dropdown
  $('.searchform .select-product ul').hover(
    function() {
      $('.searchform .select-product ul > div ').stop(true, true).slideDown();
    },
    function() {
      $('.searchform .select-product ul > div ').stop(true, true).slideUp();
    }
  );
  
});

var tryParseInt = (function(str,defaultValue) {
	var retValue = defaultValue;
	if(str!=null){         
		if(str.length>0){             
			if (!isNaN(str)){                 
				retValue = parseInt(str);             
			}         
		}     
	}     
	return retValue; 
});

var getSpotlightProductContent = (function(productID) {
	var id = 'product' + (''+productID).replace('product', '');
	var url = '/productspotlight/' + id +'.html';
	$('#productspotlight').load( url, spotlight );
});

var spotlight = (function () { 
  
  // Type Replacement 
  Cufon('.foco', { hover: true, fontFamily: 'foco' });
  Cufon('.hel', { hover: true, fontFamily: 'hel' });
  Cufon.now();
  
  
  // Session Hovers
  $('#sessions li a').hover(
    function() {
      $(this).next().delay(100).show();
    },
    function() {
      $(this).next().hide();
    }
  );
  
  // Search Dropdown
  $('#select-product ul').hover(
    function() {
      $('#select-product ul > div ').stop(true, true).slideDown();
    },
    function() {
      $('#select-product ul > div ').stop(true, true).slideUp();
    }
  );
  
  $('#select-product a').click(
    function() {
      var id = $(this).attr('id');
	  getSpotlightProductContent( id );
      return false;
    }
  );
  
  // Lightbox Controls
	$("#launch a").fancybox({
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'padding' : 0,
    'overlayOpacity' : 0.7,
    'overlayColor' : '#000000',
    'scrolling' : 'visible'
	});
	
});

var openSpotlight = (function () { 
  
	$("#launch a").trigger('click');
	
});

$(function() { 

	// On page open, check to see if spotlight=<productID> is available on the querystring
	// .. If so, automatically open the spotlight window to the desired product
	var url = document.location.href;
	var k = 'spotlight=';
	var p = url.indexOf( k );
	if( p < 0 ) return;

	// Get the product ID from the url
	url = url.substring( p + k.length, url.length );
	p = url.indexOf( '&' );
	if( p >= 0 )  url = url.substring( 0, p );
	var productID = tryParseInt( url, -1 );
	if( productID < 0 ) return;

	getSpotlightProductContent( productID );
	openSpotlight(); 

});

